package hn.cch.advanced.concurrent.locks;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.locks.LockSupport;


public class LockSupportDemo {

    private final static Logger logger = LoggerFactory.getLogger(LockSupportDemo.class);

    public static void main(String[] args) {
        logger.debug("start");
        Thread thread = new Thread(() -> {
            try {
                Thread.sleep(1000);
                logger.debug("sleep");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            logger.debug("park begin");
            LockSupport.park(); // 阻塞
            logger.debug("park end");

        }, "thread");
        thread.start();
        try {
            Thread.sleep(1000);
            logger.debug("sleep");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        logger.debug("unpark begin");
        LockSupport.unpark(thread); // 唤醒
        logger.debug("unpark end");

        logger.debug("stop");

    }
}
